(function (vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addCouponShopPoolInfo: {
                spId: '',
                poolId: '',
                shopId: '',
                couponName: '',
                actualPrice: '',
                stock: '',
                validityDay: ''
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addCouponShopPool', 'openAddCouponShopPoolModal', function () {
                $('#addCouponShopPoolModel').modal('show');
            });
        },
        methods: {
            addCouponShopPoolValidate() {
                return vc.validate.validate({
                    addCouponShopPoolInfo: $that.addCouponShopPoolInfo
                }, {
                    'addCouponShopPoolInfo.poolId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "优惠券不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "优惠券不能超过30"
                        },
                    ],
                    'addCouponShopPoolInfo.shopId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "店铺ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "店铺ID不能超过30"
                        },
                    ],
                    'addCouponShopPoolInfo.couponName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "优惠券名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "优惠券名称不能超过64"
                        },
                    ],
                    'addCouponShopPoolInfo.actualPrice': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "面值不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "10",
                            errInfo: "面值不能超过10"
                        },
                    ],
                    'addCouponShopPoolInfo.stock': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "库存不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "20",
                            errInfo: "库存不能超过20"
                        },
                    ],
                    'addCouponShopPoolInfo.validityDay': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "有效期不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "20",
                            errInfo: "有效期不能超过20"
                        },
                    ]




                });
            },
            saveCouponShopPoolInfo: function () {
                if (!$that.addCouponShopPoolValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }

                $that.addCouponShopPoolInfo.caId = vc.getCurrentCommunity().caId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addCouponShopPoolInfo);
                    $('#addCouponShopPoolModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    'couponShopPool.saveCouponShopPool',
                    JSON.stringify($that.addCouponShopPoolInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addCouponShopPoolModel').modal('hide');
                            $that.clearAddCouponShopPoolInfo();
                            vc.emit('couponShopPoolManage', 'listCouponShopPool', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddCouponShopPoolInfo: function () {
                $that.addCouponShopPoolInfo = {
                    spId: '',
                    poolId: '',
                    shopId: '',
                    couponName: '',
                    actualPrice: '',
                    stock: '',
                    validityDay: ''

                };
            }
        }
    });

})(window.vc);
